package engine

import (
	"code.google.com/p/go8/display"
	"github.com/gonutz/go-sdl2/sdl"
)

type ClockStarter interface {
	StartClock()
}

type Interpolator interface {
	Interpolate() float64
	SetBounds(min, max float64)
}

type MenuTransition struct {
	painter      display.Painter
	from, to     Image
	clock        ClockStarter
	interpolator Interpolator
}

func NewMenuTransition(p display.Painter, from, to Image) *MenuTransition {
	return &MenuTransition{painter: p, from: from, to: to}
}

func (t *MenuTransition) SetClock(c ClockStarter) {
	t.clock = c
}

func (t *MenuTransition) SetInterpolator(i Interpolator) {
	t.interpolator = i
}

func (t *MenuTransition) Enter() {
	t.clock.StartClock()
	w, _ := t.from.Size()
	t.interpolator.SetBounds(0, float64(w))
}

func (t *MenuTransition) Exit() {}

func (t *MenuTransition) HandleEvent(e sdl.Event) {}

func (t *MenuTransition) Draw() {
	w, h := t.painter.CanvasSize()
	pos := display.Rect{0, 0, w, h}
	t.from.DrawAt(pos)
	pos.X += w
	t.to.DrawAt(pos)
}
